package com.novelot.plugin.allinone;

import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.PlatformDataKeys;
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.NotNull;

public class SingletonHelper extends AnAction {
    @Override
    public void actionPerformed(@NotNull AnActionEvent e) {
        SingletonDialog dialog = new SingletonDialog();
        dialog.setListener(new SingletonDialog.Listener() {
            @Override
            public void onOK(String className) {
                createFile(e, className);
            }

            @Override
            public void onCancel() {

            }
        });
        dialog.pack();
        dialog.setVisible(true);
    }

    private void createFile(AnActionEvent e, String className) {
        VirtualFile file = e.getData(PlatformDataKeys.VIRTUAL_FILE);
        String path = file.getPath();
        if (!file.isDirectory()) {
            path = file.getParent().getPath();
        }

        FileCreater.createFile(path, className);
    }
}
